home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / random.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  1KB  |  97 lines

  1. /* --------------------------------- random.c ------------------------------- */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* Handler for the random pointing device.
  8. */
  9.  
  10. #include "fly.h"
  11.  
  12.  
  13. LOCAL_FUNC int FAR
  14. Rread (POINTER *p, int transfer)
  15. {
  16.     int    i;
  17.  
  18.     if (p->c[0] > 40) {
  19.         if (p->a[3] < 75)
  20.             p->a[3] += 5;        /* throttle up */
  21.         --p->c[0];
  22.     } else if (p->c[0] > 30) {
  23.         --p->c[0];
  24.         p->a[1] += 10;            /* pitch up */
  25.     } else if (p->c[0] > 10) {
  26.         --p->c[0];
  27.         p->a[1] -= 10;            /* pitch down */
  28.     } else if (p->c[0] > 0) {
  29.         --p->c[0];
  30.         p->a[1] += 10;            /* pitch up */
  31.     } else {
  32.         p->a[1] = 0;
  33.         p->b[1] = 0;
  34. #if 1
  35.         i = p->a[0];
  36.         if (i < 0)
  37.             ++i;
  38.         else if (i > 0)
  39.             --i;
  40.         i += (Frand () % 10) - 5;
  41.         if (i > 40)
  42.             i = 80 - i;
  43.         else if (i < -40)
  44.             i = -80 - i;
  45.         p->a[0] = i;
  46. #else
  47.         p->a[0] = 0;
  48. #endif
  49.     }
  50.     if (transfer) {
  51.         p->l[0] = p->a[0];
  52.         p->l[1] = p->a[1];
  53.         p->l[3] = p->a[3];
  54.     }
  55.  
  56.     return (0);
  57. }
  58.  
  59. LOCAL_FUNC int FAR
  60. Rcal (POINTER *p)
  61. {
  62.     p->c[0] = 90;        /* set course for 250 m/s */
  63.     p->b[0] = 0;
  64.     p->b[1] = 0;
  65.     p->l[0] = 0;
  66.     p->l[1] = 0;
  67.     p->l[0] = 0;
  68.     p->l[1] = 0;
  69.     return (0);
  70. }
  71.  
  72. LOCAL_FUNC int FAR
  73. Rinit (POINTER *p, char *options)
  74. {
  75.     return (Rcal (p));
  76. }
  77.  
  78. LOCAL_FUNC void FAR
  79. Rterm (POINTER *p)
  80. {}
  81.  
  82. LOCAL_FUNC void FAR
  83. Rkey (POINTER *p, int key)
  84. {}
  85.  
  86. struct PtrDriver NEAR PtrRandom = {
  87.     "RANDOM",
  88.     0,
  89.     NULL,    /* extra */
  90.     Rinit,
  91.     Rterm,
  92.     Rcal,
  93.     Rcal,            /* center */
  94.     Rread,
  95.     Rkey
  96. };
  97.